define(['jquery', 'bootstrap', 'frontend', 'form', 'template'], function ($, undefined, Frontend, Form, Template) {
    var Controller = {
        detail: function () {
            $('body').on('click', function(){
                $('.mini-cart-content').removeClass('showcart');
            });

            $('#add-cart').on('click', function(){
                event.preventDefault();
                let products_id = $('input[name="products_id"]').val();
                let num = $('input[name="num"]').val();

                Fast.api.ajax({
                    url: "/index/cart/add",
                    data: {
                        num: num,
                        products_id: products_id,
                    }
                }, function (data, ret) {
                    Toastr.success('Add Success');
                    let html = '';
                    for(var k in data){
                        html += '<div class="cart-products"><div class="cart-image"><a href="#">' +
                            '<img style="width: 70px;" src="'+data[k]['image']+'" alt=""></a></div>' +
                            '<div class="cart-product-info">' +
                            '<a href="#" class="product-name"> '+data[k]['name']+' </a>' +
                            '<a class="remove-product" data-products_id="'+k+'">Remove item</a>' +
                            '<div class="price-times">' +
                            '<span class="quantity"><strong> '+data[k]['num']+' x</strong></span>' +
                            '<span class="p-price">Rs.'+data[k]['price']+'</span>' +
                            '</div></div></div>';
                    }
                    $('.cart-products-list').html(html);

                    $('.mini-cart-content').addClass('showcart');

                    return false;
                }, function (data, ret) {
                    Toastr.error(ret.msg);
                    return false;
                });
            });

        }
    };
    return Controller;
});